package com.zhuoli.service.springboot.local.current.limit.service.impl;

import com.google.common.collect.Lists;
import com.zhuoli.service.springboot.local.current.limit.common.User;
import com.zhuoli.service.springboot.local.current.limit.service.UserControllerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author: zhuoli
 * @Date: 2018/9/6 13:44
 * @Description:
 */
@Service
@Slf4j
public class UserControllerServiceImpl implements UserControllerService {
    private static final List<User> userList = Lists.newArrayList();

    @PostConstruct
    public void initUserList(){
        userList.add(User.builder().id(1L).name("zhuoli0").description("zhuoli0 is a programmer").build());
        userList.add(User.builder().id(2L).name("zhuoli1").description("zhuoli1 is a programmer").build());
        userList.add(User.builder().id(3L).name("zhuoli2").description("zhuoli2 is a programmer").build());
    }

    @Override
    public User getUserById(Long id) {
        return Optional.of(userList.stream().filter(user -> user.getId().equals(id)).collect(Collectors.toList())).map(list -> list.get(0)).orElse(null);
    }
}
